package model

import "gorm.io/gorm"

// 商品表
type Good struct {
	gorm.Model
	GoodName    string  `gorm:"type:varchar(20);commit:商品名称"`
	GoodClass   int     `gorm:"type:int;commit:商品分类"`
	Price       float32 `gorm:"type:decimal(10,2);commit:商品单价"`
	Stock       int     `gorm:"type:int;commit:库存数量"`
	Description string  `gorm:"type:varchar(255);commit:商品描述"`
	ImageURL    string  `gorm:"type:varchar(255);commit:商品图片URL"`
	Status      int     `gorm:"type:int;commit:状态: 1-正常 2-封禁"`
}

// 商品分类表
type Class struct {
	gorm.Model
	ClassName string `gorm:"type:varchar(20);commit:分类名称"`
}

func (g *Good) GoodCreate(db *gorm.DB) error {
	return db.Debug().Create(&g).Error
}
func (g *Good) GoodUpdate(db *gorm.DB, id int64) error {
	return db.Debug().Where("id = ?", id).Updates(&g).Error
}
